package tw.com.msig.xml;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

public class Dom4j01App {

	public static void main(String[] args) {

		try {
			URL url = new File("C:\\temp\\sample01.xml").toURI().toURL();
			SAXReader reader = new SAXReader();
			Document document = reader.read(url);
			
			Element rootElement = document.getRootElement();
			String policyNumber = rootElement.element("policyNumber").getText();
			
			List<Element> list = rootElement.element("insureds").elements("insured");
			
			System.out.println("list.size:"+list.size());
			
			for(Element element :list){
				System.out.println(element.element("idNo").getText());
			}
			
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (DocumentException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}

	}

}
